package com.jueyunqi.jredis;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSONObject;
import com.jueyunqi.dao.User;
import com.jueyunqi.dao.UserDAO;

@Service("userDAO")
public class UserDAOImpl implements UserDAO
{
	@Resource
	private RedisClientTemplate redisClientTemplate;
	
	@Override
	public void saveUser(User user)
	{
		redisClientTemplate.set("user.uid." + user.getId(), JSONObject.toJSONString(user));
	}

	@Override
	public User getUser(long id)
	{
		String json = redisClientTemplate.get("user.uid." + id);
		return JSONObject.parseObject(json, User.class);
	}

}
